<?php
class personal
{
	
	public $name;
	
	public function personal(){
		
		if (isset($_SESSION['username'])){
			$this->name = $_SESSION['username'];
			//echo $/this->name;
			//session_destroy();
			$this->ver();
		}
		else{
			include_once 'views/view-inicio.php';
			$inicio = new view_inicio();
			$inicio->text = 'no has iniciado sesion';
			$inicio->ver();
		}
	}
	
	public function ver(){
?>
<html>
<head>
<title>Personal </title>	
</head>
	<body style="background-color:#009900">
     	<div style="position:absolute; left: 10px; width: 20%; top:10px; height:20%; background-color:#0C0">
          <table width="100%" height="100%" align="center">
          	<tr align="center">
          		<td>
          			<h2><?= $this->name; ?><br></h2>
          		</td>
          	</tr>
               <tr align="center">
               	<td>
               		<a href="?action=close">cerrar sesion</a>
               	</td>
               </tr>
          </table>
          </div>
          
          <div style="position:absolute; left:21%; top:10px; height:20%; width:78%; background-color:#0C0">
          <table width="100%" height="100%">
          	<tr align="center" style="font-size:24px">
               	<td>
                    	<a href="index.php?action=entrar">Menu</a>
                    </td>
                    <td>
                    	<a href="?action=ver_usuarios">Usuarios</a>
                    </td>
                    <td>
                    	<a href="">Repostes</a>
                    </td>
          	</tr>
          </table>
          </div>
          
          
          <div style="position:absolute; left:10px; top:22%; background-color:#0C0; width:98.3%; height:77%;">
          <table width="100%" border = "1" style="background-color:#999">
          <tr bgcolor="#00CC00">
          	<td colspan="8">
               <a href="?action=add_personal">agregar nuevo</a>
               </td>
          </tr>
          <tr height="7%">
          <th>ID</th>
          <th>Nombre</th>
          <th>Apellido</th>
          <th>Puesto</th>
          <th>Sueldo</th>
          <th>Medida de tiepo</th>
          <th>tiempo en horas</th>
          <th>acciones</th>
          </tr>
          <?php
			include_once 'class/class.conecction.php';
			$conection = new conexion();
			$query = "SELECT * FROM personal ORDER BY nombre";
			$result = $conection->ejecutar($query);
			while ($res = mysql_fetch_object($result)){
				$array_personal[] = $res;
			}
			foreach ($array_personal as $key => $r){	
			
				?>
				<tr align="center" bgcolor="#CCCCCC">
                    	<td>
						<?= $r->id?>
					</td>
					<td>
						<?= $r->nombre?>
					</td>
                         <td>
						<?= $r->apellido?>
					</td>
                         <td>
						<?= $r->puesto?>
					</td>
					<td>
						<?= $r->sueldo?>
					</td>
                         <td>
						<?= $r->tipo_tiempo?>
					</td>
                         <td>
						<?= $r->tiempo_horas?>
					</td>
                         <td>
                         	<a href="?action=borrar_personal&id=<?=$r->id?>">borrar</a> / 
                         	<a href="?action=add_personal&id=<?=$r->id?>">editar</a>
                         </td>
				</tr>
			<?php 
				
			}
			
			
			?>
          	
          </table>         
          </div>
          
</body>

</html>

<?php 
	}
}
?>